import {request} from "../../request/index"
Page({
  data: {
    goods: [],
    isFocus: false,
    inputValue: ''
  },
  TimeId: -1,
  handleInput(e) {
    console.log(e.detail);
    const { value } = e.detail
    if (!value.trim()) {
      this.setData({
        goods: [],
        isFocus: false
      })
      return
    }
    this.setData({
      isFocus: true
    })
    clearTimeout(this.TimeId)

    this.TimeId = setTimeout(() => {
      this.qsearch(value)
    }, 1000);
  },
  async qsearch(query) {
    const res = await request({
      url: '/goods/qsearch',
      data: {
        query
      }
    })
    this.setData({
      goods: res
    })
  },
  handleCancel() {
    this.setData({
      inputValue: '',
      isFocus: false,
      goods: []
    })
  }
})